﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyUtils;

namespace Test.MyUtils
{
	[TestClass]
	public class IntToBytes
	{
		[TestMethod]
		public void TestToBytes0()
		{
			var simple = 0.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(0, simple[0]);
			Assert.AreEqual(0, simple[1]);
			Assert.AreEqual(0, simple[2]);
			Assert.AreEqual(0, simple[3]);
		}

		[TestMethod]
		public void TestToBytes1()
		{
			var simple = 15.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(15, simple[0]);
			Assert.AreEqual(0, simple[1]);
			Assert.AreEqual(0, simple[2]);
			Assert.AreEqual(0, simple[3]);
		}

		[TestMethod]
		public void TestToBytes2()
		{
			var simple = 254.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(254, simple[0]);
			Assert.AreEqual(0, simple[1]);
			Assert.AreEqual(0, simple[2]);
			Assert.AreEqual(0, simple[3]);
		}

		[TestMethod]
		public void TestToBytes3()
		{
			var simple = 255.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(255, simple[0]);
			Assert.AreEqual(0, simple[1]);
			Assert.AreEqual(0, simple[2]);
			Assert.AreEqual(0, simple[3]);
		}

		[TestMethod]
		public void TestToBytes4()
		{
			var simple = 256.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(0, simple[0]);
			Assert.AreEqual(1, simple[1]);
			Assert.AreEqual(0, simple[2]);
			Assert.AreEqual(0, simple[3]);
		}

		[TestMethod]
		public void TestToBytes5()
		{
			var simple = 257.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(1, simple[0]);
			Assert.AreEqual(1, simple[1]);
			Assert.AreEqual(0, simple[2]);
			Assert.AreEqual(0, simple[3]);
		}

		[TestMethod]
		public void TestToBytes6()
		{
			var simple = int.MaxValue.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(255, simple[0]);
			Assert.AreEqual(255, simple[1]);
			Assert.AreEqual(255, simple[2]);
			Assert.AreEqual(0x7f, simple[3]);
		}

		[TestMethod]
		public void TestToBytes7()
		{
			var simple = (-257).ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(0xff, simple[0]);
			Assert.AreEqual(0xfe, simple[1]);
			Assert.AreEqual(0xff, simple[2]);
			Assert.AreEqual(0xff, simple[3]);
		}

		[TestMethod]
		public void TestToBytes8()
		{
			var simple = int.MinValue.ToBytes();
			Assert.AreEqual(4, simple.Length);
			Assert.AreEqual(0, simple[0]);
			Assert.AreEqual(0, simple[1]);
			Assert.AreEqual(0, simple[2]);
			Assert.AreEqual(0x80, simple[3]);
		}

		[TestMethod]
		public void TestToInt0()
		{
			Assert.AreEqual(0, new byte[] { 0, 0, 0, 0 }.ToInt());
		}

		[TestMethod]
		public void TestToInt1()
		{
			Assert.AreEqual(15, new byte[] { 15, 0, 0, 0 }.ToInt());
		}

		[TestMethod]
		public void TestToInt2()
		{
			Assert.AreEqual(254, new byte[] { 254, 0, 0, 0 }.ToInt());
		}

		[TestMethod]
		public void TestToInt3()
		{
			Assert.AreEqual(255, new byte[] { 255, 0, 0, 0 }.ToInt());
		}

		[TestMethod]
		public void TestToInt4()
		{
			Assert.AreEqual(256, new byte[] { 0, 1, 0, 0 }.ToInt());
		}

		[TestMethod]
		public void TestToInt5()
		{
			Assert.AreEqual(257, new byte[] { 1, 1, 0, 0 }.ToInt());
		}

		[TestMethod]
		public void TestToInt6()
		{
			Assert.AreEqual(int.MaxValue, new byte[] { 255, 255, 255, 0x7f }.ToInt());
		}

		[TestMethod]
		public void TestToInt7()
		{
			Assert.AreEqual(-257, new byte[] { 0xff, 0xfe, 0xff, 0xff }.ToInt());
		}

		[TestMethod]
		public void TestToInt8()
		{
			Assert.AreEqual(int.MinValue, new byte[] { 0, 0, 0, 0x80 }.ToInt());
		}

	}

//	[TestClass]
//	public class UShortToBytes
//	{
//		[TestMethod]
//		public void TestToBytes0()
//		{
//			var simple = ((ushort)0).ToBytes();
//			Assert.AreEqual(2, simple.Length);
//			Assert.AreEqual(0, simple[0]);
//			Assert.AreEqual(0, simple[1]);
//		}
//
//		[TestMethod]
//		public void TestToBytes1()
//		{
//			var simple = ((ushort)15).ToBytes();
//			Assert.AreEqual(2, simple.Length);
//			Assert.AreEqual(15, simple[0]);
//			Assert.AreEqual(0, simple[1]);
//		}
//
//		[TestMethod]
//		public void TestToBytes2()
//		{
//			var simple = ((ushort)254).ToBytes();
//			Assert.AreEqual(2, simple.Length);
//			Assert.AreEqual(254, simple[0]);
//			Assert.AreEqual(0, simple[1]);
//		}
//
//		[TestMethod]
//		public void TestToBytes3()
//		{
//			var simple = ((ushort)255).ToBytes();
//			Assert.AreEqual(2, simple.Length);
//			Assert.AreEqual(255, simple[0]);
//			Assert.AreEqual(0, simple[1]);
//		}
//
//		[TestMethod]
//		public void TestToBytes4()
//		{
//			var simple = ((ushort)256).ToBytes();
//			Assert.AreEqual(2, simple.Length);
//			Assert.AreEqual(0, simple[0]);
//			Assert.AreEqual(1, simple[1]);
//		}
//
//		[TestMethod]
//		public void TestToBytes5()
//		{
//			var simple = ((ushort)257).ToBytes();
//			Assert.AreEqual(2, simple.Length);
//			Assert.AreEqual(1, simple[0]);
//			Assert.AreEqual(1, simple[1]);
//		}
//
//		[TestMethod]
//		public void TestToBytes6()
//		{
//			var simple = ushort.MaxValue.ToBytes();
//			Assert.AreEqual(2, simple.Length);
//			Assert.AreEqual(255, simple[0]);
//			Assert.AreEqual(255, simple[1]);
//		}
//
//		[TestMethod]
//		public void TestToInt0()
//		{
//			Assert.AreEqual<ushort>(0, new byte[] { 0, 0 }.ToUShort());
//		}
//
//		[TestMethod]
//		public void TestToInt1()
//		{
//			Assert.AreEqual<ushort>(15, new byte[] { 15, 0 }.ToUShort());
//		}
//
//		[TestMethod]
//		public void TestToInt2()
//		{
//			Assert.AreEqual<ushort>(254, new byte[] { 254, 0 }.ToUShort());
//		}
//
//		[TestMethod]
//		public void TestToInt3()
//		{
//			Assert.AreEqual<ushort>(255, new byte[] { 255, 0 }.ToUShort());
//		}
//
//		[TestMethod]
//		public void TestToInt4()
//		{
//			Assert.AreEqual<ushort>(256, new byte[] { 0, 1 }.ToUShort());
//		}
//
//		[TestMethod]
//		public void TestToInt5()
//		{
//			Assert.AreEqual<ushort>(257, new byte[] { 1, 1 }.ToUShort());
//		}
//
//		[TestMethod]
//		public void TestToInt6()
//		{
//			Assert.AreEqual<ushort>(ushort.MaxValue, new byte[] { 255, 255 }.ToUShort());
//		}
//
//	}
}
